package com.gxa.service.Impl;

import com.gxa.common.base.LayuiResultJson;
import com.gxa.common.base.Result;
import com.gxa.domain.entity.Coach;
import com.gxa.domain.vo.FindCoachByNameVO;
import com.gxa.domain.vo.FindUserByNameVO;
import com.gxa.mapper.CoachMapper;
import com.gxa.service.CoachService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Date;
import java.util.List;
@Service
public class CoachServiceImpl implements CoachService {
    @Autowired
    private CoachMapper coachMapper;
    @Override
    public Result selectAllUsersById(Integer id) {
        Coach coach=coachMapper.queryById(id);
        return Result.success(coach);

    }


    @Override
    public Result updateCoach(Coach coach) {

        int result=coachMapper.updateCoach(coach);
        if (result>0){
            return Result.success("更新成功");
        }
        return Result.error("更新失败");
    }

    @Override
    public Result deleteCoachById(Integer id) {

        int result=coachMapper.deleteCoachById(id);
        if (result>0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    @Override
    public Result insertCoach(Coach coach) {

        System.out.println("进入教练增加serviceImpl");
        int result=coachMapper.insertCoach(coach);
        if (result>0){
            System.out.println("教练增加成功");
            return Result.success("添加成功");
        }
        System.out.println("教练增加失败");
        return Result.error("添加失败");

    }

    @Override
    public List<Coach> getCoachList() {
        return coachMapper.getCoachList();
    }

    @Override
    public List<Coach> getoachListByPage(int pageNum, int pageSize) {
        int start = (pageNum - 1) * pageSize;
        return coachMapper.getCoachListByPage(start,pageSize);
    }

    @Override
    public int countCoachs() {
        return coachMapper.countCoachs();
    }



    @Override
    public LayuiResultJson findCoachByName(String title, int page, int limit) {
        Integer offset = (page - 1) * limit;
        Integer rows = limit;
        List<FindCoachByNameVO> findCoacbByNameVO= coachMapper.findCoachByName(title,offset,rows);
        Integer totalSize = coachMapper.countCoachByCondition(title);
        LayuiResultJson R = new LayuiResultJson();
        R.setCode(0);
        R.setMsg("");
        R.setCount(totalSize);
        R.setData(findCoacbByNameVO);

        return R;
    }

    public Result update(Coach coach) {
        int result = coachMapper.updateSysUser(coach);
        if(result > 0 ){
            return Result.success("修改成功！");
        }
        return Result.error();
    }

}


